<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
<link href="./css/common.css" rel="stylesheet"  />
<link href="../../css/buttons.css" rel="stylesheet"  />
<script type="text/javascript" src="../../js/util.js"></script>
<script type="text/javascript" src="../../js/new-ajax.js"></script>
<script type="text/javascript" src="../../js/business-poweritem.js"></script>
<script type="text/javascript">
function createPanel(){
	createDetail(0);
}
function createDetail(pid,step){
	for(var i=0;i<menuItems.length;i++){
		if(menuItems[i].pid==pid){
			createPowerItemLine(menuItems[i],step?step:0);
			createDetail(menuItems[i].id,(step?step:0)+1);
		}
	}
}
function createPowerItemLine(powerItem,step){
	var powerDeployPanel=dqbb.$("powerDeployPanel");
	var checked=" checked='checked' ";
	if(powerItem.iss != 1){
		checked="";
	}
	powerDeployPanel.innerHTML+=stepToSpace(step?step:0)+"<input type='checkbox' "+ checked +" pid='"+ powerItem.pid +"' onclick='selectOthers(this)' name='powerItem' value='"+ powerItem.id +"' id='pid_"+powerItem.id+"' /><label for='pid_"+ powerItem.id +"'>"+powerItem.text+"</label><br/>";
}
function stepToSpace(step){
	var buffer="";
	for(var i=0;i<step;i++){
		buffer+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}
	return buffer;
}

function selectOthers(chkbox){
	selectSubs(chkbox);
	selectSuper(chkbox);
}
//遍历子节点
function selectSubs(chkbox){
	var pid=chkbox.value;
	var powerItems=document.getElementsByName("powerItem");
	for(var i=0;i<powerItems.length;i++){
		if(pid==powerItems[i].getAttribute("pid")){
			powerItems[i].checked=chkbox.checked;
			selectSubs(powerItems[i]);
		}
	}
}
//遍历父节点
function selectSuper(chkbox){
	if(!chkbox.checked)
		return ;
	var pid=chkbox.getAttribute("pid");
	var powerItems=document.getElementsByName("powerItem");
	for(var i=0;i<powerItems.length;i++){
		if(pid==powerItems[i].value){
			powerItems[i].checked=true;
			selectSuper(powerItems[i]);
		}
	}
}

window.onload=function(){
	createPanel();
};

function saveData(){
	var data=[];
	var powerItems=document.getElementsByName("powerItem");
	for(var i=0;i<powerItems.length;i++){
		if(powerItems[i].checked){
			data.push(powerItems[i].value);
		}
	}
	alert("您选择了下面功能点：\n"+data.join("\n"));
}
</script>
</head>
<body>
<form onsubmit="return false">
<table cellpadding="0" cellspacing="1" border="0" width="100%">
	<tr class="th">
		<td colspan="2">功能点分配</td>
	</tr>
	<tr class="tb">
		<td width="80">当前角色</td>
		<td>总经理</td>
	</tr>
	<tr class="tb">
		<td>分配</td>
		<td>
			<div id="powerDeployPanel"></div>
		</td>
	</tr>
	<tr class="tf">
		<td>&nbsp;</td>
		<td>
			<input type="button" value="" onclick="saveData()" class="save" />
			<input type="reset" value="" class="reset" />
		</td>
	</tr>
</table>
</form>
</body>
</html>